package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.tradewar.UserTradeWarPatronsData;
import com.yanqu.road.entity.tradewar.*;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.pb.tradewar.TradeWarProto;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.List;

public class TradeWarPb {

	public static TradeWarProto.TradeWarTempMsg.Builder parseTradeWarTempMsg(UserTradeWarInfo userTradeWarInfo) {
		if(null == userTradeWarInfo){
			return null;
		}
		TradeWarProto.TradeWarTempMsg.Builder msg = TradeWarProto.TradeWarTempMsg.newBuilder();
		msg.setScore(userTradeWarInfo.getScore());
		msg.setCrossTradeWarMoney(userTradeWarInfo.getCrossTradeWarMoney());
		msg.setTrackTimes(userTradeWarInfo.getDailyTrackTimes());
		return msg;
	}

	public static TradeWarProto.TradeWarRecordTempMsg.Builder parseTradeWarRecordTempMsg(UserTradeWarRecord record) {
		if(null == record){
			return null;
		}
		TradeWarProto.TradeWarRecordTempMsg.Builder msg = TradeWarProto.TradeWarRecordTempMsg.newBuilder();
		msg.setRecordUid(record.getRecordUid());
		msg.setBattleType(record.getBattleType());
		msg.setEnemyUserId(record.getEnemyUserId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(record.getEnemyBaseData());
		msg.setEnemyBaseData(baseMsg);
		msg.setEnemyScore(record.getEnemyScore());
		msg.setKillPatronsCount(record.getKillPatronsCount());
		msg.setLoseScore(record.getLoseScore());
		msg.setRecordTime(record.getRecordTime());
		msg.setIsBattle(record.isBattle());

		return msg;
	}

	public static TradeWarProto.TradeWarRecordListMsg.Builder parseTradeWarRecordListMsg(List<UserTradeWarRecord> recordList) {
		TradeWarProto.TradeWarRecordListMsg.Builder listMsg = TradeWarProto.TradeWarRecordListMsg.newBuilder();
		if(null != recordList) {
			for (UserTradeWarRecord record : recordList) {
				TradeWarProto.TradeWarRecordTempMsg.Builder msg = parseTradeWarRecordTempMsg(record);
				if (null != msg) {
					listMsg.addBattleRecordList(msg);
				}
			}
		}
		return listMsg;
	}

	public static TradeWarProto.TradeWarNoticeTempMsg.Builder parseTradeWarNoticeTempMsg(TradeWarNotice notice) {
		if(null == notice){
			return null;
		}
		TradeWarProto.TradeWarNoticeTempMsg.Builder msg = TradeWarProto.TradeWarNoticeTempMsg.newBuilder();
		msg.setUserId(notice.getUserId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(notice.getUserBaseInfo());
		msg.setPlayerBaseData(baseMsg);
		msg.setKillPatronsCount(notice.getKillPatronsCount());
		msg.setNoticeTime(notice.getNoticeTime());
		baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(notice.getEnemyBaseInfo());
		msg.setEnemyBaseData(baseMsg);
		msg.setBattleType(notice.getBattleType());
		msg.setIsAllKill(notice.isAllKill());
		msg.setTotalKillPatronsCount(notice.getTotalKillPatronsCount());
		msg.setTotalChallengeTimes(notice.getTotalChallengeTimes());
		msg.setEnemyUserId(notice.getEnemyUserId());
		return msg;
	}

	public static TradeWarProto.TradeWarNoticeListMsg.Builder parseTradeWarNoticeListMsg(List<TradeWarNotice> noticeList) {
		TradeWarProto.TradeWarNoticeListMsg.Builder listMsg = TradeWarProto.TradeWarNoticeListMsg.newBuilder();
		if(null != noticeList) {
			for (TradeWarNotice notice : noticeList) {
				TradeWarProto.TradeWarNoticeTempMsg.Builder msg = parseTradeWarNoticeTempMsg(notice);
				if (null != msg) {
					listMsg.addBattleNoticeList(msg);
				}
			}
		}
		return listMsg;
	}

	public static TradeWarProto.TradeWarWantedTempMsg.Builder parseTradeWarWantedTempMsg(TradeWarWanted wanted) {
		if(null == wanted){
			return null;
		}
		TradeWarProto.TradeWarWantedTempMsg.Builder msg = TradeWarProto.TradeWarWantedTempMsg.newBuilder();
		msg.setWantedUid(wanted.getWantedUid());
		msg.setUserId(wanted.getUserId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(wanted.getUserBaseInfo());
		msg.setPlayerBaseData(baseMsg);
		msg.setWantedUserId(wanted.getWantedUserId());
		baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(wanted.getWantedBaseInfo());
		msg.setWantedBaseData(baseMsg);
		msg.setWantedScore(wanted.getWantedScore());
		msg.setWantedTime(wanted.getWantedTime());
		msg.setBattleTimes(wanted.getBattleTimes());
		msg.setReward(wanted.getReward());
		msg.setTrackTimes(0);
		msg.setActivityId(wanted.getActivityId());
		msg .setUseItemId(wanted.getUseItemId());
		return msg;
	}

	public static TradeWarWanted parseTradeWarWanted(TradeWarProto.TradeWarWantedTempMsg wantedTempMsg){
		TradeWarWanted data = new TradeWarWanted();
		data.setWantedUid(wantedTempMsg.getWantedUid());
		data.setUserId(wantedTempMsg.getUserId());
		data.setUserBaseInfo(PlayerBasePb.parseToUserBaseInfo(wantedTempMsg.getPlayerBaseData()));
		data.setWantedUserId(wantedTempMsg.getWantedUserId());
		data.setWantedBaseInfo(PlayerBasePb.parseToUserBaseInfo(wantedTempMsg.getWantedBaseData()));
		data.setWantedScore(wantedTempMsg.getWantedScore());
		data.setWantedTime(wantedTempMsg.getWantedTime());
		data.setBattleTimes(wantedTempMsg.getBattleTimes());
		data.setReward(wantedTempMsg.getReward());
		data.setActivityId(wantedTempMsg.getActivityId());
		data.setUseItemId(wantedTempMsg.getUseItemId());
		return data;
	}

	public static TradeWarProto.TradeWarTrackRecordTempMsg.Builder parseTradeWarTrackRecordTempMsg(TradeWarTrackRecord trackRecord) {
		if(null == trackRecord){
			return null;
		}
		TradeWarProto.TradeWarTrackRecordTempMsg.Builder msg = TradeWarProto.TradeWarTrackRecordTempMsg.newBuilder();
		msg.setWantedUid(trackRecord.getWantedUid());
		msg.setUserId(trackRecord.getUserId());

		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(trackRecord.getUserBaseInfo());
		msg.setPlayerBaseData(baseMsg);
		msg.setKillPatronsCount(trackRecord.getKillPatronsCount());
		msg.setLoseScore(trackRecord.getLoseScore());
		msg.setRecordTime(trackRecord.getRecordTime());
		return msg;
	}

	public static TradeWarProto.TradeWarWantedNotifyMsg.Builder parseTradeWarWantedNotifyMsg(boolean isBeWanted, TradeWarWanted wanted) {
		if(null == wanted){
			return null;
		}
		TradeWarProto.TradeWarWantedNotifyMsg.Builder msg = TradeWarProto.TradeWarWantedNotifyMsg.newBuilder();
		msg.setIsBeWanted(isBeWanted);
		TradeWarProto.TradeWarWantedTempMsg.Builder wantedMsg = parseTradeWarWantedTempMsg(wanted);
		if(null != wantedMsg){
			msg.setWantedInfo(wantedMsg);
		}
		return msg;
	}

	public static TradeWarProto.TradeWarWantedListMsg.Builder parseTradeWarWantedListMsg(List<TradeWarWanted> wantedList) {
		TradeWarProto.TradeWarWantedListMsg.Builder listMsg = TradeWarProto.TradeWarWantedListMsg.newBuilder();
		if(null != wantedList) {
			for (TradeWarWanted wanted : wantedList) {
				TradeWarProto.TradeWarWantedTempMsg.Builder msg = parseTradeWarWantedTempMsg(wanted);
				if (null != msg) {
					listMsg.addWantedList(msg);
				}
			}
		}
		return listMsg;
	}

	public static TradeWarProto.TradeWarPatronsDataTempMsg.Builder parseTradeWarPatronsDataTempMsg(UserTradeWarPatronsData userTradeWarPatronsData){
		if(null == userTradeWarPatronsData){
			return null;
		}
        TradeWarProto.TradeWarPatronsDataTempMsg.Builder msg = TradeWarProto.TradeWarPatronsDataTempMsg.newBuilder();
		msg.setPatronsId(userTradeWarPatronsData.getPatronsId());
		msg.setBattleTimes(userTradeWarPatronsData.getBattleTimes());
		msg.setBuyBattleTimes(userTradeWarPatronsData.getBuyBattleTimes());
		msg.setRandomBattleTimes(userTradeWarPatronsData.getRandomBattleTimes());
		msg.setRandomBattleRestoreTimes(userTradeWarPatronsData.getRandomBattleRestoreTimes());
		msg.setRestoreRandomBattleTime(userTradeWarPatronsData.getRestoreRandomBattleTime());

		return msg;
	}

	public static TradeWarProto.TradeWarPatronsDataListMsg.Builder parseTradeWarPatronsDataListMsg(List<UserTradeWarPatronsData> userTradeWarPatronsDataList){
        TradeWarProto.TradeWarPatronsDataListMsg.Builder listMsg = TradeWarProto.TradeWarPatronsDataListMsg.newBuilder();
		if(null != userTradeWarPatronsDataList){
			for(UserTradeWarPatronsData userTradeWarPatronsData : userTradeWarPatronsDataList){
                TradeWarProto.TradeWarPatronsDataTempMsg.Builder msg = parseTradeWarPatronsDataTempMsg(userTradeWarPatronsData);
				if(null != msg){
					listMsg.addPatronsDataList(msg);
				}
			}
		}
		return listMsg;
	}

	public static TradeWarProto.TradeWarBuildingTempMsg.Builder parseTradeWarBuildingTempMsg(UserTradeWarBuilding userTradeWarBuilding) {
		if(null == userTradeWarBuilding){
			return null;
		}
		TradeWarProto.TradeWarBuildingTempMsg.Builder msg = TradeWarProto.TradeWarBuildingTempMsg.newBuilder();
		msg.setType(userTradeWarBuilding.getType());
		msg.setLevel(userTradeWarBuilding.getLevel());
		msg.setLastGetRewardTime(userTradeWarBuilding.getLastGetTime());
		msg.setValue(userTradeWarBuilding.getLastValue().toString());
		msg.setLastCalcRewardTime(userTradeWarBuilding.getLastValueChangeTime());
		return msg;
	}

	public static TradeWarProto.TradeWarBuildingListMsg.Builder parseTradeWarBuildingListMsg(List<UserTradeWarBuilding> userTradeWarBuildingList){
		TradeWarProto.TradeWarBuildingListMsg.Builder listMsg = TradeWarProto.TradeWarBuildingListMsg.newBuilder();
		if(null != userTradeWarBuildingList){
			for(UserTradeWarBuilding userTradeWarBuilding : userTradeWarBuildingList){
				TradeWarProto.TradeWarBuildingTempMsg.Builder msg = parseTradeWarBuildingTempMsg(userTradeWarBuilding);
				if(null != msg){
					listMsg.addBuildingList(msg);
				}
			}
		}
		return listMsg;
	}

	public static TradeWarProto.TradeWarEnemyRecordTempMsg.Builder parseTradeWarEnemyRecordTempMsg(UserTradeWarEnemyRecord userTradeWarEnemyRecord) {
		if(null == userTradeWarEnemyRecord){
			return null;
		}
		TradeWarProto.TradeWarEnemyRecordTempMsg.Builder msg = TradeWarProto.TradeWarEnemyRecordTempMsg.newBuilder();
		msg.setEnemyUserId(userTradeWarEnemyRecord.getEnemyUserId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(userTradeWarEnemyRecord.getEnemyBaseInfo());
		msg.setEnemyBaseData(baseMsg);
		msg.setEnemyScore(userTradeWarEnemyRecord.getEnemyScore());
		msg.setTotalFightTimes(userTradeWarEnemyRecord.getTotalFightTimes());
		msg.setFightBackTimes(userTradeWarEnemyRecord.getFightBackTimes());

		return msg;
	}

	public static TradeWarProto.TradeWarEnemyRecordListMsg.Builder parseTradeWarEnemyRecordListMsg(List<UserTradeWarEnemyRecord> recordList) {
		TradeWarProto.TradeWarEnemyRecordListMsg.Builder listMsg = TradeWarProto.TradeWarEnemyRecordListMsg.newBuilder();
		if(null != recordList) {
			for (UserTradeWarEnemyRecord record : recordList) {
				TradeWarProto.TradeWarEnemyRecordTempMsg.Builder msg = parseTradeWarEnemyRecordTempMsg(record);
				if (null != msg) {
					listMsg.addRecordList(msg);
				}
			}
		}
		return listMsg;
	}

	public static TradeWarProto.TradeWarSimpleNoticeTempMsg.Builder parseTradeWarSimpleNoticeTempMsg(TradeWarSimpleNotice data){
		if(null == data){
			return null;
		}
		TradeWarProto.TradeWarSimpleNoticeTempMsg.Builder msg = TradeWarProto.TradeWarSimpleNoticeTempMsg.newBuilder();
		msg.setUserId(data.getUserId());
		msg.setEnemyUserId(data.getEnemyUserId());
		msg.setKillPatronsCount(data.getKillPatronsCount());
		msg.setNoticeTime(data.getNoticeTime());
		return msg;
	}

	public static TradeWarProto.TradeWarSimpleNoticeListMsg.Builder parseTradeWarSimpleNoticeListMsg(List<TradeWarSimpleNotice> dataList){
		TradeWarProto.TradeWarSimpleNoticeListMsg.Builder listMsg = TradeWarProto.TradeWarSimpleNoticeListMsg.newBuilder();
		if(null != dataList){
			for(TradeWarSimpleNotice data : dataList){
				TradeWarProto.TradeWarSimpleNoticeTempMsg.Builder msg = parseTradeWarSimpleNoticeTempMsg(data);
				if(null != msg){
					listMsg.addDataList(msg);
				}
			}
		}
		return listMsg;
	}
}
